package com.akw.boot3.rpc.service;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@Service
public class WeatherService {

    public Mono<String> weather(String city) {
        WebClient client = WebClient.create("https://ali-weather.showapi.com/area-to-weather-date");

//        client.get()
//                .accept(MediaType.APPLICATION_JSON)
//                .header("Authorization", "APPCODE c03432821c7a48e58d68c12ce083b35b")
//                .attribute("area", city);
        Mono<String> stringMono = client.get()
                .uri(uriBuilder -> uriBuilder
                        .path("")
                        .queryParam("area", city)
                        .build())
                .header("Authorization", "APPCODE c03432821c7a48e58d68c12ce083b35b")
                .retrieve()
                .bodyToMono(String.class);
        return stringMono;
    }

    public String getWeather(String city) {
        return "";
    }
}
